<template>
  <div>
    <el-table
      :data="list"
      border
      stripe
      show-summary
      :summary-method="getSummaries"
      style="width: 100%">
      <el-table-column
        prop="city_name"
        label="城市"
        align="center">
      </el-table-column>

      <el-table-column
        prop="agent_name"
        label="代理商"
        align="center">
      </el-table-column>

      <el-table-column
        v-if="type === 'month'"
        prop="show_month"
        label="月份"
        width="120"
        align="center">
      </el-table-column>

      <el-table-column
        v-if="type === 'week'"
        prop="week_num"
        label="周"
        width="120"
        align="center">
        <template slot-scope="{row}">
          <p>{{row.week_num}}周</p>
          <p>{{row.week_start.slice(5)}} ~ {{row.week_end.slice(5)}}</p>
        </template>
      </el-table-column>

      <el-table-column
        v-if="type === 'day'"
        prop="show_day"
        label="日期"
        width="120"
        align="center">
      </el-table-column>

      <el-table-column label="灵活儿" align="center">
        <el-table-column
          prop="flexible_amass_register"
          label="累计注册人才" align="center">
        </el-table-column>
        <el-table-column
          prop="flexible_new_register"
          label="新注册人才" align="center">
        </el-table-column>
        <el-table-column
          prop="flexible_new_register_ratio"
          label="注册人才环比" align="center">
          <template slot-scope="{row}">
            <span>{{row.flexible_new_register_ratio}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="flexible_amass_audit"
          label="累计审核人才" align="center">
        </el-table-column>
        <el-table-column
          prop="flexible_new_audit"
          label="新已审核人才" align="center">
        </el-table-column>
        <el-table-column
          prop="flexible_new_audit_ratio"
          label="新审核环比" align="center">
          <template slot-scope="{row}"><span>{{row.flexible_new_audit_ratio}}</span></template>
        </el-table-column>
        <el-table-column
          prop="flexible_amass_work"
          label="累计出工人才" align="center">
        </el-table-column>
        <el-table-column
          prop="flexible_new_work"
          label="新出工人才" align="center">
        </el-table-column>
        <el-table-column
          prop="flexible_new_work_ratio"
          label="新出工环比" align="center">
          <template slot-scope="{row}"><span>{{row.flexible_new_work_ratio}}</span></template>
        </el-table-column>
      </el-table-column>

      <el-table-column
        prop="name"
        label="灵活管家"
        align="center">
        <el-table-column
          prop="housekeeper_amass_work"
          label="累计出工人才" align="center">
        </el-table-column>
        <el-table-column
          prop="housekeeper_new_work"
          label="新出工人才" align="center">
        </el-table-column>
        <el-table-column
          prop="housekeeper_new_work_ratio"
          label="新出工环比" align="center">
          <template slot-scope="{row}"><span>{{row.housekeeper_new_work_ratio}}</span></template>
        </el-table-column>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'StaffTable',
  props: {
    type: {
      type: String,
      default: 'month'
    },
    list: {
      type: Array,
      default: () => []
    },
    aggregate: {
      type: Object,
      default: () => {}
    },
    page: {
      type: Number,
      default: 1,
    },
    pageSize: {
      type: Number,
      default: 20,
    },
    total: {
      type: Number,
      default: 0
    },
  },
  methods: {
    handleSizeChange(size) {
      this.$emit('page-size', {size, type: this.type})
    },
    handleCurrentChange(page) {
      this.$emit('page-num', {page, type: this.type})
    },
    getSummaries() {
      try {
        return [
          '总计', '-', '-',
          this.aggregate.flexible_amass_register,
          this.aggregate.flexible_new_register,
          this.aggregate.flexible_new_register_ratio || '-',
          this.aggregate.flexible_amass_audit,
          this.aggregate.flexible_new_audit,
          this.aggregate.flexible_amass_new_ratio || '-',
          this.aggregate.flexible_amass_work,
          this.aggregate.flexible_new_work,
          this.aggregate.flexible_new_work_ratio || '-',
          this.aggregate.housekeeper_amass_work,
          this.aggregate.housekeeper_new_work,
          this.aggregate.housekeeper_new_work_ratio || '-',
        ]
      } catch (err) {
      }
    }
  }
}
</script>

<style scoped lang="scss">
.el-table {
  >>> .el-table__body-wrapper {
    min-height: auto;
  }
}
.el-pagination {
  margin-top: 20px;
  width: 100%;
  display: flex;
  justify-content: flex-end;
}
</style>



// WEBPACK FOOTER //
// src/components/sheet/staff/StaffTable.vue